<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateProductsDiscount extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('prod_categories', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('catename')->default('')->nullable(false)->comment('商品英文名');
            $table->string('catename_zn')->default('')->nullable(false)->comment('商品中文名');
            $table->timestamps();
        });
        DB::statement("alter table `prod_categories` comment '商品分类表' ");

        Schema::create('products', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('cids')->default('')->nullable(false)->comment('商品拥有的分类ID,以半圆角逗号隔开');
            $table->string('proname')->default('')->nullable(false)->comment('商品英文名');
            $table->string('proname_zn')->default('')->nullable(false)->comment('商品中文名');
            $table->string('image')->default('')->nullable(false)->comment('商品主图');
            $table->unsignedInteger('mprice')->default(0)->nullable(false)->comment('商品价格,单位为分');
            $table->unsignedInteger('rprice')->default(0)->nullable(false)->comment('活动价格,单位为分');
            $table->unsignedInteger('salenum')->default(0)->nullable(false)->comment('商品销量');
            $table->text('content')->comment('商品详情');
            $table->softDeletes();
            $table->timestamps();
        });
        DB::statement("alter table `products` comment '商品列表' ");

        Schema::create('prod_discounts', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->integer('levid')->default(0)->nullable(false)->comment('用户等级ID');
            $table->integer('proid')->default(0)->nullable(false)->comment('商品ID');
            $table->tinyInteger('discount')->default(0)->nullable(false)->comment('折扣值');
            $table->timestamps();
        });
        DB::statement("alter table `prod_discounts` comment '商品折扣列表' ");

        Schema::create('jifen_products', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('proname')->default('')->nullable(false)->comment('商品英文名');
            $table->string('proname_zn')->default('')->nullable(false)->comment('商品中文名');
            $table->string('image')->default('')->nullable(false)->comment('商品主图');
            $table->unsignedInteger('price')->default(0)->nullable(false)->comment('商品价格,单位为分');
            $table->unsignedInteger('coin')->default(0)->nullable(false)->comment('所需积分');
            $table->unsignedInteger('salenum')->default(0)->nullable(false)->comment('已兑换数量');
            $table->text('content')->comment('商品详情');
            $table->softDeletes();
            $table->timestamps();
        });
        DB::statement("alter table `jifen_products` comment '积分商品列表'");

        Schema::create('dinings', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('title')->default('')->nullable(false)->comment('餐桌英文名');
            $table->string('title_zn')->default('')->nullable(false)->comment('餐桌中文名');
            $table->string('image')->default('')->nullable(false)->comment('餐桌主图');
            $table->tinyInteger('sitnum')->default(1)->nullable(false)->comment('餐桌可坐人数');
            $table->timestamps();
            $table->engine = 'InnoDB';
        });
        DB::statement("alter table `dinings` comment '餐桌列表'");

        Schema::create('dining_reserves', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->bigInteger('uid')->default(0)->nullable(false)->comment('用户ID');
            $table->bigInteger('tid')->default(0)->nullable(false)->comment('餐桌ID');
            $table->tinyInteger('timetype')->default(1)->nullable(false)->comment('就餐时间段 1,2,3,4四个时间段');
            $table->date('sitday')->nullable(false)->comment('就餐日期');
            $table->tinyInteger('pernum')->default(1)->nullable(false)->comment('就餐人数');
            $table->string('ordersn')->default('')->unique()->nullable(false)->comment('订单编号');
            $table->bigInteger('earnest')->default(0)->nullable(false)->comment('订金(单位分)');
            $table->bigInteger('total')->default(0)->nullable(false)->comment('应付总金额(单位分)');
            $table->tinyInteger('status')->default(0)->nullable(false)->comment('订单状态  0待付款 1待接单 2待进餐 3待结账 4已结账 5退订 6取消订单');
            $table->tinyInteger('ordtype')->default(2)->nullable(false)->comment('预定类型  1预定 2现场点餐');
            $table->string('remark')->default('')->nullable(false)->comment('备注');
            $table->timestamps();
            $table->engine = 'InnoDB';
        });
        DB::statement("alter table `dining_reserves` comment '餐桌预定信息'");

        Schema::create('dining_reserve_prods', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->bigInteger('did')->default(0)->nullable(false)->comment('预定ID');
            $table->Integer('proid')->default(1)->nullable(false)->comment('商品ID');
            $table->bigInteger('proprice')->default(1)->nullable(false)->comment('商品实际价格(元)');
            $table->Integer('pronum')->default(1)->nullable(false)->comment('商品数量');
            $table->tinyInteger('status')->default(0)->nullable(false)->comment('商品状态 0申请中 1待审核 2待付款 3已付款 4已退 5已存');
            $table->timestamps();
            $table->engine = 'InnoDB';
        });
        DB::statement("alter table `dining_reserve_prods` comment '餐桌商品预定信息'");

        Schema::create('images', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('title')->default('')->nullable(false)->comment('图片英文名');
            $table->string('title_zn')->default('')->nullable(false)->comment('图片中文名');
            $table->string('src')->default('')->nullable(false)->comment('图片链接地址');
            $table->unsignedTinyInteger('type')->default(1)->nullable(false)->comment('图片类型:1为商品图片,2为积分商品图片,3为广告图片,4为用户头像');
            $table->unsignedBigInteger('rid')->default(0)->nullable(false)->comment('关联表的ID');
            $table->timestamps();
        });
        DB::statement("alter table `images` comment '图片列表'");
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('prod_categories');
        Schema::dropIfExists('products');
        Schema::dropIfExists('prod_discounts');
        Schema::dropIfExists('jifen_products');
        Schema::dropIfExists('dinings');
        Schema::dropIfExists('dining_reserves');
        Schema::dropIfExists('dining_reserve_prods');
        Schema::dropIfExists('images');
    }
}
